﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MyDelegateDemo
{
    /// <summary>
    /// 学生类
    /// </summary>
    public class Student
    {
        public int Id { get; set; }
        public string? Name { get; set; }
        public int ClassId { get; set; }
        public int Age { get; set; }


        /// <summary>
        /// 礼貌性的打招呼~~  方案二;
        /// </summary>
        public void SayHi(UserType userType)    
        {
            Console.WriteLine("招招手~");
            switch (userType)
            {
                case UserType.Wuhan:
                    Console.WriteLine("过早了吗~~~");

                    break;
                case UserType.GuangDong:
                    Console.WriteLine("雷猴~~~");

                    break;
                case UserType.Beijin:

                    Console.WriteLine("你好~~~");
                    break;
                default:
                    throw new Exception("No UserType");
            }
        }

        /// <summary>
        /// 定义好的委托
        /// </summary>
        public delegate void SayHiMehtod();


        //需求一:新增一个地方的人: 新增方法--不影响历史代码---保持代码的稳定;
        //需求二:增加公共的业务逻辑: 只需要在SayHiPerfact方法中,增加业务逻辑,可以覆盖全部, 没有重复代码;

        //自上而下:
        //完美方案: 方法的职责更单一,  逻辑解耦.----保证代码的稳定性
        //充分的使用了委托的特点: 就是可以把行为逻辑进行传递;


        /// <summary>
        /// 完美方案: 
        /// 传递逻辑
        /// </summary>
        //public void SayHiPerfact(SayHiMehtod mehtod)
        //{
        //    Console.WriteLine("招招手~~");
        //    mehtod.Invoke(); //执行委托
        //}

        public void SayHiPerfact(Action mehtod)
        {
            Console.WriteLine("招招手~~");
            mehtod.Invoke(); //执行委托
        }

        //自下而上: 相比于完美方案:
        //优势: 代码复用---去掉重复代码;




        //以下: 方案一: 可以为每个地方的人各自定义一个方法;
        /// <summary>
        /// 武汉人打招呼
        /// </summary>
        public void SayHiWuHan()
        {
            //Console.WriteLine("招招手");
            Console.WriteLine("过早了吗~~~");
        }
         
        /// <summary>
        /// 广东人打招呼
        /// </summary>
        public void SayHiGuangDong()
        {
            //Console.WriteLine("招招手");
            Console.WriteLine("雷猴~~~");
        }

        /// <summary>
        /// 北京人打招呼
        /// </summary>
        public void SayHiBeiJing()
        {
            //Console.WriteLine("招招手");
            Console.WriteLine("你好~~~");
        }

        /// <summary>
        /// 上海人打招呼
        /// </summary>
        public void SayHiShangHai()
        {
            //Console.WriteLine("招招手");
            Console.WriteLine("侬好~~~~");
        }













        public void Study()
        {
            Console.WriteLine("和Richard老师一起学习高级开发~~");
        }

        public static void StaticStudy(object? obj)
        {
            Console.WriteLine($"this is StaticStudy...{obj}");
        }

        public void InstanceStudy(object? obj)
        {
            Console.WriteLine($"this is InstanceStudy...{obj}");
        }

        public void StudyFramework()
        {
            Console.WriteLine("和Eleven老师一起学习如何做一个架构师~~");
        }
    }

    public enum UserType
    {
        Wuhan,
        GuangDong,
        Beijin
        
    }
}
